<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.jframe.sso.model.CurUser" %>
<%
String contextPath = request.getContextPath();
CurUser user = (CurUser)session.getAttribute("curUser");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户组管理</title>
<jsp:include page="/inc/inc.jsp" />
<script type="text/javascript" src="jframe/sso/list/js/userList.js"></script>
<script type="text/javascript">
var contextPath = '<%=contextPath%>';
var action = 'userAction';
var vo=[];
$(function(){
	loadTree();	
	<%=request.getAttribute("js")%> 
}); 

function add(){
	showWin('新增',contextPath+'/jframe/sso/edit/userEdit.jsp?id=0&type=add&groupId='+tabId_,600,300);
}

function edit(){
	var rows = $('#grid').datagrid('getSelections');
	if(rows.length>1){
		alertWarn("请您只选择一条记录进行操作！");
		return;
	}else if(rows.length==0){
		alertError("请您选择要操作的记录！");
		return;
	}
	var id = getSelection();
	showWin('编辑',contextPath+'/jframe/sso/edit/userEdit.jsp?groupId='+tabId_+'&type=edit&id='+id,600,300);
}
 
function del(){
	var ids = getSelections();
	if(ids==""){
		alertError("请您选择要操作的记录！");
		return;
	}else{
		econfirm('警告','确定要删除所选择的数据？',function(r){
    		if(r){
    			var url = action+".do?method=delete";
    			$.ajax({
    				url:url,
    		 		type: 'post',
    			    data:{
    			    	ids:ids
    			    },
    			    dataType: 'json',
    			    error: function(){
    			        alertError('删除失败!');
    			    },
    			    success: function(data){
    			    	alertInfo('成功删除所选记录！');
    			    	$('#grid').datagrid('reload');
    			    }
    			});
    		}
    	});
		$('#grid').datagrid('clearSelections');
	}	
}

function find(){
	vo=[];
	var name = $('#userName').val();
	var active = $('#active').combobox('getValue');
	if(name!=null&&name!="")
		vo.push({name:'userName',type:'String',logic:'and',operators:'like',value:name});
	if(active!=null&&active!="")
		vo.push({name:'active',type:'int',logic:'and',operators:'=',value:active});	
    $('#grid').datagrid('load',{
        conditions: obj2json(vo)
   });
}

<%
if(user.getRoleId()==1||user.getRoleId()==2){
%>
var loadTree = function(){
	var setting = {
            data: {
                    simpleData: {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: 0
                    }
            },
            async: { 
                    type: "post",
                    enable: true,
                    url: 'userAction.do?method=getRightTrees&groupId='+tabId_,
                    otherParam: {}
            },
            callback : {
                onClick: callback
            }
    };
    $.fn.zTree.init($("#mtree"), setting);//初始化树对象a
};
<%
}else{
%>
var loadTree = function(){
	makeTree(action+'.do?method=makeIndexTree','mtree',callback);
}
<%
}
%>

var callback = function(event,treeId,node){
	vo=[];
	vo.push({name:'roleId',type:'int',logic:'and',operators:'=',value:node.id});	
	$('#grid').datagrid('load',{
	       conditions: obj2json(vo)
	});
}

function changePwd(){
	var rows = $('#grid').datagrid('getSelections');
	if(rows.length>1){
		alertWarn("请您只选择一条记录进行操作！");
		return;
	}else if(rows.length==0){
		alertError("请您选择要操作的记录！");
		return;
	}
	var id = getSelection();
	showWin('编辑',contextPath+'/jframe/sso/edit/changePwd.jsp?groupId='+tabId_+'&type=edit&id='+id,400,300);
}

</script>
</head>
<body class="easyui-layout"> 
	<div region="west" border="true" title="系统角色" class="cs-west" style="width:180px;height: 100%" border="false">
		<ul id="mtree"  class='ztree'></ul>
	</div>
	<div  region="center" border="true" border="false" style="height:100%">
	<div id="tb">
	     <a class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>
		 <a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
		 <a class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a>
		 <a class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="changePwd()">密码修改</a><br>
		 <span>名称：</span><input id="userName" name="userName" type="text" style="width: 100px;">
		 <span>有效否：</span>
		 <select id="active" name="active" class="easyui-combobox" style="width:100px;">
			 <option value=""></option>
			 <option value="1">有效</option>
			 <option value="0">无效</option>
		 </select>
		 <a class="easyui-linkbutton" plain="true" onclick="find()" iconCls="icon-search">查询</a>
	</div>
	<table id="grid" toolbar="#tb" border="0"></table>
	</div>
</body>
</html>